package org.hadoop.dft;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class DefaultMR extends Configured implements Tool {
    @Override
    public int run(String[] args) throws Exception {
        if(args.length!=2){
            System.out.println("usage : <in> <out>");
            return -1;
        }
        Configuration conf = getConf();
        Job job = Job.getInstance(conf,"DefaultMR");
        job.setJarByClass(this.getClass());
        //
        FileSystem fs = FileSystem.get(conf);
        if(fs.exists(new Path(args[1]))){
            fs.delete(new Path(args[1]),true);
        }
        //
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        int code = job.waitForCompletion(true)?0:1;
        return code;
    }

    public static void main(String[] args) throws  Exception {
        int code = ToolRunner.run(new DefaultMR(),args);
        System.exit(code);
    }
}
